package com.ihr360.insurance.dao;

import com.ihr360.insurance.model.dto.benefits.MandatoryBenefitsMode;
import com.ihr360.rest.reposity.SimpleRestReposity;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;

import java.util.Date;
import java.util.List;

/**
 * @author Stone.Shi
 * @description
 * @date 2018-01-11 15:41:22.
 */
@RepositoryRestResource
public interface MandatoryBenefitsModeReposity extends SimpleRestReposity<MandatoryBenefitsMode, Long>, PagingAndSortingRepository<MandatoryBenefitsMode, Long> {

    int countByCode(String code);

    int countByName(String name);

    @Query(" select t from MandatoryBenefitsMode t where t.effectiveAt <= :nowDate and (t.invalidAt > :nowDate or t.invalidAt is null)")
    List<MandatoryBenefitsMode> getCurrentValidModes(@Param("nowDate") Date nowDate);
}
